home *** CD-ROM | disk | FTP | other *** search
/ Gekkan Dennou Club 147 / Gekkan Dennou Club - 2000.8 Vol. 147 (Japan).7z / Gekkan Dennou Club - 2000.8 Vol. 147 (Japan) (Track 1).bin / docs / ippon / ver / 012 / ippon012.lzh / player.c < prev    next >
C/C++ Source or Header  |  2000-07-07  |  3KB  |  126 lines

  1. /* player.c */
  2.  
  3. #include <sys/iocs.h>
  4. #include <xsp2lib.h>
  5.  
  6. #include "main.h"
  7. #include "player.h"
  8. #include "shot.h"
  9.  
  10. #define PLAYER_BANK1    8    /* 少し傾きパターンへ移行するまでの値 */
  11. #define PLAYER_BANK2    12    /* 一番傾きパターンへ以下同文 */
  12.  
  13. #define PLAYER_SPEED    15    /* 自機の速度 */
  14. #define PLAYER_PALET    0x0700    /* 自機のパレット */
  15.  
  16.  
  17. enum {
  18.     PLAYER_PT_RIGHT2 = 0,    /* 自機が一番右に傾いている時のパターン */
  19.     PLAYER_PT_RIGHT1,    /*  〃 少し右に     〃      */
  20.     PLAYER_PT_CENTER,    /*  〃 正面を向いている時のパターン */
  21.     PLAYER_PT_LEFT1,    /* 自機が少し右に傾いている時のパターン */
  22.     PLAYER_PT_LEFT2        /*  〃 一番右に     〃      */
  23. };
  24.  
  25.  
  26.  
  27. /* ゲーム開始時に呼ばれる */
  28. void PlayerInit (void)
  29. {
  30. }
  31.  
  32.  
  33.  
  34. /* プレイヤー出現時に呼ばれる */
  35. void PlayerAlloc (void)
  36. {
  37.     player->lx = 144 * 65536;
  38.     player->ly = 144 * 65536;
  39.     player->bank = 0;
  40. }
  41.  
  42.  
  43.  
  44. /* 垂直同期ごとに呼ばれる */
  45. void PlayerMove (void)
  46. {
  47.     int j;            /* ジョイスティックの入力 */
  48.  
  49.     j = _iocs_joyget (0);    /* ジョイスティック0番 */
  50.  
  51.     /* [A] ボタンが押されたか? */
  52.     if ((j & 0b00100000) == 0)
  53.         game_over = !0;    /* ゲームオーバーに */
  54.  
  55.     /* [B] ボタンが押されたか? */
  56.     if ((j & 0b1000000) == 0)
  57.         ShotAlloc();
  58.  
  59.     /* 自機の上下移動処理 */
  60.     switch (j & 0b0011) {
  61.     case 0b0010:        /* 上 */
  62.         player->ly += xytable[PLAYER_SPEED][192].y;
  63.         break;
  64.     case 0b0001:        /* 下 */
  65.         player->ly += xytable[PLAYER_SPEED][64].y;
  66.         break;
  67.     default:        /* それ以外 */
  68.         break;
  69.     }
  70.  
  71.     /* 自機の左右移動処理+左右傾き処理 */
  72.     switch (j & 0b1100) {
  73.     case 0b1000:        /* 左 */
  74.         player->lx += xytable[PLAYER_SPEED][128].x;
  75.         if (player->bank > 0) {
  76.             player->bank = 0;
  77.         } else {
  78.             if (player->bank > -PLAYER_BANK2)
  79.                 player->bank--;
  80.         }
  81.         break;
  82.  
  83.     case 0b0100:        /* 右 */
  84.         player->lx += xytable[PLAYER_SPEED][0].x;
  85.         if (player->bank < 0) {
  86.             player->bank = 0;
  87.         } else {
  88.             if (player->bank < PLAYER_BANK2)
  89.                 player->bank++;
  90.         }
  91.         break;
  92.  
  93.     default:        /* それ以外 */
  94.         /* 自機の傾きを元に戻す処理 */
  95.         if (player->bank != 0) {
  96.             if (player->bank > 0)
  97.                 player->bank--;
  98.             else
  99.                 player->bank++;
  100.         }
  101.         break;
  102.     }
  103.  
  104.     /* 自機の傾き (player->bank) から自機の複合スプライトNo.を求める */
  105.     if (player->bank == 0) {
  106.         player->pt = obj_player + PLAYER_PT_CENTER;
  107.     } else {
  108.         if (player->bank > 0) {
  109.             if (player->bank < PLAYER_BANK1)
  110.                 player->pt = obj_player + PLAYER_PT_LEFT1;
  111.             else
  112.                 player->pt = obj_player + PLAYER_PT_LEFT2;
  113.         } else {
  114.             if (player->bank > -PLAYER_BANK1)
  115.                 player->pt = obj_player + PLAYER_PT_RIGHT1;
  116.             else
  117.                 player->pt = obj_player + PLAYER_PT_RIGHT2;
  118.         }
  119.     }
  120.  
  121.     player->x = player->lx / 65536;
  122.     player->y = player->ly / 65536;
  123.  
  124.     xobj_set (player->x, player->y, player->pt, PLAYER_PALET | PRIORITY_PLAYER);    /* 自機を表示 */
  125. }
  126.